<template>
  <div ref="app_sec" class="app-sec"  style="width: 100%;height: 80%;"></div>
</template>

<script>
import * as echarts from "echarts";
import { mapState } from "vuex";
export default {
  data() {
    return {
      chartInstance: null,
    };
  },
  computed: {
    ...mapState(["theme"]),
  },
  methods: {
    initChart() {
      // 初始化对象
      this.chartInstance = echarts.init(this.$refs.app_sec, this.theme);
      let option = {
        color: ["#21ffeb", "#36adff"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          bottom: "2%",
          textStyle: {
            color: "rgba(255,255,255,0.8)",
          },
          icon:'circle'
        },

        grid: {
          left: "3%",
          right: "0%",
          bottom: "20%",
          top: "5%",
          containLabel: true,
        },

        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: [
              "07-12",
              "07-13",
              "07-14",
              "07-15",
              "07-16",
              "07-17",
              "07-18",
            ],
            axisTick: {
              show: false,
            },
            axisLabel: {
              show: true, color: "rgba(255,255,255,0.5)",

            },
            axisLine: {
              show: false,
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            axisLabel: {
              show: true, color: "rgba(255,255,255,0.5)",

            },
            splitLine: {
              lineStyle: {
                color: "#1a1f6d",
                width: 1,
              },
            },
            scale: true,
          },
        ],
        calculable: true,
        series: [
          {
            name: "规格参数",
            barWidth: 10,
            type: "bar",
            data: [120, 203, 209, 209, 240, 260, 300],
            symbol: "circle",
            itemStyle: {
              /*      color: arg => {
                return new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  // 0%
                  { offset: 0, color: '#00FFFF '},
                  // 100%
                  { offset: 1, color: '#070C61' }
                ])
              }*/
            },
          },
          {
            name: "服务参数",
            barWidth: 10,
            type: "bar",
            data: [210, 213, 219, 218, 200, 214, 320],
            symbol: "circle",
          },
        ],
      };
      this.chartInstance.setOption(option);
    },
  },
  mounted() {
    this.initChart();
        // 添加随页面变化而变化
    window.addEventListener('resize', () => {
       this.chartInstance.resize()
    })
  },
      destroyed () {
    window.removeEventListener("resize", () => {
      this.chartInstance.resize();
    });
  },
  watch: {
    theme(newValue, oldValue) {
      this.chartInstance.dispose();
      this.initChart();
    },
  },
};
</script>

<style lang="scss" scoped>
.app-sec {
  width: 100%;
  height: 80%;
}
</style>
